# barco/srcrepos.py

import sys
import optparse
import barco.error
import barco.srcrepos

## main() ##
def main():
    client = barco.srcrepos.Client()
    
    usage = list()
    usage.append('usage: srcrepos [options] <command> [args]')
    usage.append('')
    usage.append('Valid srcrepos commands are:')
    usage.append('')
    usage.append('  create_module <name>   Creates a new module in the source repository')
    usage.append('  create_branch <name>   Creates a new branch in the source repository')
    usage.append('  list_modules           List all source modules in the repositoy')
    usage.append('  list_branches          List all branches in the repository')

    parser = optparse.OptionParser(usage='\n'.join(usage), version='0.1')
    (option, args) = parser.parse_args()

    # list_modules is our default command
    if len(args) == 0: args = [ 'list_modules' ]

    # make sure our commands are lowercase
    command = args[0].lower()

    try:
        
        if command == 'create_module': client.create_module(*args[1:])
        elif command == 'create_branch': client.create_branch(*args[1:])
        elif command == 'list_modules' : client.list_modules(*args[1:])
        elif command == 'list_branches': client.list_branches(*args[1:])
        else: parser.error('invalid command specified: [%s]' % args[0])

    except barco.error.Error as e: parser.error(str(e))
    return 0

# execute main() if we are being run as standalone script.
if __name__ == '__main__': sys.exit(main())
